package com.pingan.pastry.common.util;


import com.pingan.pastry.entity.User;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;


public class UserUtil {

    public static User getCurrentUser() {
        //springMvc 的用法
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        String sessionId = request.getSession().getId();
        User currentUser = (User) request.getSession().getAttribute(sessionId);
        return currentUser;
    }
}
